import axios from "axios";

//创建一个实例
const instance = axios.create({
    baseURL: 'http://gz.wolfcode.cn/cms',
    timeout: 5000,
    // headers: { "Content-Type": "application/x-www-form-urlencoded" }
});

//设置请求拦截器
instance.interceptors.request.use((config) => {
    // console.log(config);
    if (config.url === '/sendSMS' || config.url === '/phoneRegin' || config.url === '/wechatUsers/PCLogin') {
        config.headers["Content-Type"] = 'application/x-www-form-urlencoded'
    }


    //如果已登录，带上请求头
    const token = localStorage.getItem('x-auth-token')
    if (token) {
        config.headers['x-auth-token'] = token
    }
    return config
})

//设置响应拦截
instance.interceptors.response.use((res) => {
    // console.log(res);
    return res.data
})


export default instance